﻿using System;
using GiveAQuiz.Client.Data.DataServices;
using GiveAQuiz.Common;
using System.Collections.Generic;

namespace GiveAQuiz.QuizManager.Interfaces
{
  public interface IQuizModel
  {
    /// <summary>
    /// Retrieves a Quiz Definition for editing.
    /// </summary>
    /// <param name="id">The id of the QuizDefinition</param>
    /// <param name="callback">The callback on success or failure.</param>
    void GetQuizDefinitionAsync(int id, Action<QuizDefinition, Exception> callback);

    /// <summary>
    /// Retrieves a Quiz for taking a test.
    /// </summary>
    /// <param name="id">The id of the Quiz</param>
    /// <param name="callback">The callback on success or failure.</param>
    void GetQuizAsync(int id, Action<Quiz, Exception> callback);
    
    /// <summary>
    /// Adds a new Quiz to the model so it can be saved later.
    /// </summary>
    /// <param name="callback"></param>
    void AddQuizToModel(QuizDefinition quiz);

    /// <summary>
    /// Adds answers to the data model so they
    /// will be saved on a Save operation.
    /// </summary>
    /// <param name="answers">A collection of the answers to be added.</param>
    void AddQuizAnswersToModel(IEnumerable<QuizAnswer> answers);

    /// <summary>
    /// Saves all changes in the model.
    /// </summary>
    /// <param name="callback">Callback on success or failure.</param>
    void SaveAsync(Action<Exception> callback);

    /// <summary>
    /// Creates a new QuestionDefinition and attaches it to be saved
    /// when the model is updated.
    /// </summary>
    /// <param name="type">The question type to be used in the new
    /// definition.</param>
    /// <returns>A valid QuestionDefinition based on the type.</returns>
    QuestionDefinition CreateQuestionDefinition(IQuestionType type);

    /// <summary>
    /// Removes a QuestionDefinition from the model.
    /// </summary>
    /// <param name="def">The question to remove.</param>
    void DeleteQuestionDefinition(QuestionDefinition def);

    /// <summary>
    /// Adds a new QuizResult to the Context so it can be tracked.
    /// </summary>
    /// <param name="quiz">The Quiz that is used in the result.</param>
    /// <param name="name">The name of the person taking the quiz.</param>
    /// <param name="email">The email of the person taking the quiz.</param>
    /// <param name="lastVisit">The time that the quiz was taken.</param>
    /// <returns>The new QuizResult object.</returns>
    QuizResult CreateQuizResult(Quiz quiz, string name, string email, DateTime lastVisit);


    /// <summary>
    /// Checks to see if the quiz taker has already taken this quiz.  If so
    /// it returns a false.
    /// </summary>
    /// <param name="quizId">The quiz to take.</param>
    /// <param name="email">The quiz taker's e-mail address.</param>
    /// <param name="callback">Callback that contains the result of the call.</param>
    void CanTakeQuizAsync(int quizId, string email, Action<bool, Exception> callback);
  }
}
